package com.zhiwang.planet.widget.highlight.shape;

import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.RectF;

import com.zhiwang.planet.widget.highlight.HighLight;

/**
 * Created by caizepeng on 16/8/20.
 * Edited by isanwenyu@163.com 16/10/26.
 */
public class CircleLightShape extends BaseLightShape {
    private int padding = 0;

    public CircleLightShape() {
        super();
    }

    public CircleLightShape(int padding) {
        this.padding = padding;
    }

    public CircleLightShape(float dx, float dy) {
        super(dx, dy);
    }

    public CircleLightShape(float dx, float dy, float blurRadius) {
        super(dx, dy, blurRadius);
    }

    @Override
    protected void drawShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setDither(true);
        paint.setAntiAlias(true);
        if (blurRadius > 0) {
            paint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID));
        }
        RectF rectF = viewPosInfo.rectF;
        float radius = Math.min(rectF.width(), rectF.height()) / 2;
        canvas.drawCircle(rectF.left + radius, rectF.top + radius,
                radius + padding, paint);
    }

    @Override
    protected void resetRectF4Shape(RectF viewPosInfoRectF, float dx, float dy) {
        viewPosInfoRectF.inset(dx, dy);
    }

    @Override
    public boolean overlayShape(Bitmap bitmap, HighLight.ViewPosInfo viewPosInfo) {
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(4f);
        paint.setColor(Color.WHITE);
        paint.setDither(true);
        paint.setAntiAlias(true);
        paint.setPathEffect(new DashPathEffect(new float[]{10f, 10f}, 1));
//        if (blurRadius > 0) {
//            paint.setMaskFilter(ic_generate_new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID));
//        }
        RectF rectF = viewPosInfo.rectF;
        float radius = Math.min(rectF.width(), rectF.height()) / 2;
        canvas.drawCircle(rectF.left + radius, rectF.top + radius,
                radius + padding, paint);
        return true;

    }
}
